<template>
	<view>
		<navbar :config="config" backColor="#000000"></navbar>
		<view class="balance-top">
			<view class="balance">
			<view class="balance-nums">{{ $addDecimals(balance , 2) }}</view>
			<view class="balance-title">消费额</view>
			</view>
			<view class="balance-btns" v-if="cnhd_outcome_enabled">

<!-- 				<view class="balance-btn" @click.stop="goBalancePay()">
					去转入
				</view> -->
				<view   @click.stop="goBalanceExchange()" >
					转出消费额
				</view>

			</view>
		</view>
		<consume-list title="余额明细" :status="status" :list="pointsList" :keys="{title:'remark',time:'formatCreateTimeMillis',val:'entryValue',type:'billType'}"></consume-list>
		
	</view>
</template>

<script>
	import {
		refillCardInfo
	} from "@/api/personal-center.js"
	import {
		getAccountInfo
	} from "@/api/login.js"
import { re } from "mathjs";
	export default {
		data() {
			return {
				cnhd_outcome_enabled:false,
				zydc_income_enabled: false,
				zydc_outcome_enabled:false,
				zydc_to_balance_enabled:false,
				zydc_to_worth_enabled:false,
				balance: 0,
				voucher: 0,
				config: {
					back: true, //false是tolbar页面 是则不写
					title: '消费额',
					color: '#000',
					//背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
					backgroundColor: [1, "#fff"],
					statusBarFontColor: '#1A1A1A',
					backIconColor: "#000"
				},
				params: {
					page: 1,
					limit: 10
				},
				pointsList:[],
				status: 'loading', //more|loading|noMore
			};
		},
		onShow() {
			this.getUserInfo()
			this.params.page = 1;
			this.pointsList = [];
			this.getList();
			this.configInfo()
		},
		onReachBottom() {
			if ( this.status !== 'loading' && this.status !== 'noMore') {
				this.params.page++
				this.getList()
			}
		},
		onPullDownRefresh() {
			this.params.page = 1
			this.pointsList = []
			this.getList()
		},
		methods: {
			configInfo(){
				this.$http.get('/app/config/info').then(res => {
					if (res && res.code == 200) {
						
						
						
						this.cnhd_outcome_enabled=res.data.cnhd_outcome_enabled
						this.zydc_income_enabled=res.data.zydc_income_enabled
						this.zydc_outcome_enabled=res.data.zydc_outcome_enabled
						this.zydc_to_balance_enabled=res.data.zydc_to_balance_enabled
						this.zydc_to_worth_enabled=res.data.zydc_to_worth_enabled
						
						
						
					}
				})
			},
			getList(){
				this.status = 'loading';
				this.$http.get(refillCardInfo, this.params).then((res) => {
					if (res && res.code == 200) {
						uni.stopPullDownRefresh()
						this.pointsList = this.pointsList.concat(res.page.list);
						if (res.page.totalPage <= res.page.currPage) {
							this.status = 'noMore'
						} else {
							this.status = 'more'
						}
					}
				});
			},
			//获取个人信息
			getUserInfo() {
				this.$http.get(getAccountInfo).then(res => {
					if (res && res.code == 200) {
						this.balance = res.data.balance;
						this.voucher = res.data.voucher;
						
						uni.setStorageSync("personal", res.data)
					} else {
						this.isLogin = false
					}
				})
			},

			// 余额转入
			goBalancePay() {
				uni.navigateTo({
					url: "/pages/user/Pay",
					fail: err => {
						console.log('goBalanceExchange = ', err)
					}
				})
			},
			// 余额转赠
			goBalanceExchange() {

				uni.navigateTo({
					// url: "/pages/user/exchangetoMSN/exchangetoMSN",
					url: "/pages/user/submit/submitcnhd",
					fail: err => {
						console.log('goBalanceExchange = ', err)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	.balance-top {
		font-weight: 400;
		color: #ffffff;
		width: 712rpx;
		height: auto;
		background: #FFFFFF;
		border-radius: 19rpx 19rpx 19rpx 19rpx;
		margin-top: 19rpx;
		margin-left: 19rpx;
		padding-top: 57rpx;
		box-sizing: border-box;
		padding-bottom: 38rpx;
		
		.balance-title {
			font-weight: 400;
			font-size: 27rpx;
			line-height: 27rpx;
			color: #333333;
			margin-top: 20rpx;
		}

		.balance-nums {
			font-weight: bold;
			font-size: 59rpx;
			color: #FF211F;
			line-height: 59rpx;
		}

		.balance-btns {
			width: 635rpx;
			height: 85rpx;
			background: #FF211F;
			border-radius: 19rpx 19rpx 19rpx 19rpx;
			font-weight: 500;
			font-size: 29rpx;
			color: #FFFFFF;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			margin:0 auto;
			margin-top: 96rpx;
			.balance-btn {
				width: 270rpx;
				height: 70rpx;
				// background: #3775f6;
				border: 1rpx solid #ffffff;
				border-radius: 36rpx;
				text-align: center;
				line-height: 68rpx;
				font-size: 26rpx;
			}

			.exchange-btn {
				background-color: #fff;
				color: #FF721B;
			}
		}

		// <view class="balance-top">
		// 	<text class="balance-title">余额（元）</text>
		// 	<text class="balance-nums">4974.00</text>
		// 	 <view class="balance-btns">
		// 	 	<view class="balance-btn">
		// 	 		去转入
		// 	 	</view>
		// 		<view class="balance-btn">
		// 			余额转赠
		// 		</view>
		// 	 </view>
		// </view>

	}
	.balance{
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
	}
</style>
